package com.zeng.createmd.restfulmodule.controller;

import com.zeng.createmd.restfulmodule.itemCache.ItemCache;
import com.zeng.createmd.restfulmodule.util.ItemUtil;
import com.zeng.createmd.restfulmodule.util.ProjectUtil;
import com.zeng.createmd.servicemodule.vo.ItemVo;
import com.zeng.nicecommon.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping
@RestController
public class ItemController {

    @Autowired
    ItemUtil itemUtil;

    @RequestMapping
    public Object detail(String code) {
        ItemVo detail = itemUtil.detail(code);
        ItemCache.currentItem = detail;
        return ResponseUtil.success("操作成功").addData("detail", detail);
    }
    @RequestMapping
    public Object item() {
        if (ItemCache.currentItem == null) {
            throw new RuntimeException("尚未选择项目");
        }
        return ResponseUtil.success("操作成功").addData("detail", ItemCache.currentItem);
    }

    @RequestMapping
    public Object projectUtilDetail() {
        Map<String, Object> data = new ProjectUtil().getData();
        return ResponseUtil.success("操作成功").addData("data", data).addData("project", ItemCache.currentItem);
    }

}
